/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


$(document).ready(function(){
    //   alert('haha');

    
    /********************/
    $('.info').live("click",function(){
        var content=$(this).attr('content');
        var cartProduct = $("#cartParagraph").attr('content');
        $('.infoDiv').fadeIn(1000);
        $('#opacityDiv').slideDown('slow');
        $('.infoDiv').html("<img src=\"images/loading.gif\" width=\"50px\" style=\"display:block; margin:auto; border-radius:3px; margin-top:200px;\"/>");
        //        $('.infoDiv').fadeIn('slow');
        $.ajax(
        {
            url:'inc/getProduct.php',
            data:"id="+content,
            type: 'post',
            success: function(j){
                //                        $('.infoDiv').html("<img src=\"images/loading.gif\" width=\"50px\" style=\"display:block; margin:auto; border-radius:3px;\"/>");
                $('.infoDiv').html(j);
            }
        });
    });
    /////////
    /////////
    $('#opacityDiv').click(function(){
        $('.infoDiv').fadeOut('fast');
        $('#opacityDiv').slideUp('slow');
    });
    $('.infoDivButtons').live("click",function(){
        $('.infoDiv').fadeOut('fast');
        $('#opacityDiv').slideUp('slow');
    });
    ////////
    ////////
  
    
    $(".buy").live("click",function() //click on add button
    {
	
        $(this).removeClass('buy');
        $(this).val('delete');
        $(this).addClass('delete');
        
        var content1=$(this).attr('content');//get product id
        $.ajax(
        {
            url:'inc/addToCart.php',
            data:"id="+content1,
            type: 'post',
            success: function(j){
                $(".cartNav").html(j) //if prssed add , imidiately incr card
            }
        });
    });
    
    
    $(".delete").live("click",function()
    {
           
//        alert('hada delete');
        $(this).removeClass('delete');
        $(this).val('add');
        $(this).addClass('buy');
        var content=$(this).attr('content');
        $.ajax(
        {
            url:'inc/deleteFromCart.php',
            data:"id="+content,
            type: 'post',
            success: function(j){
                $(".cartNav").html(j)
            }
        });
    });
});